//
//  PopTransitionAnimation.m
//  29-TransitionAnimation
//
//  Created by Snow on 16/8/23.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "PopTransitionAnimation.h"
#import "ViewController.h"
#import "SecondViewController.h"
@implementation PopTransitionAnimation
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
    return 0.5f;
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    SecondViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    ViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *containerView = [transitionContext containerView];
    [containerView addSubview:toVC.view];
    toVC.FromVC.hidden = YES;
    UIView *snapView = [fromVC.ToVCImageView snapshotViewAfterScreenUpdates:NO];
    snapView.frame = fromVC.ToVCImageView.frame;
    [containerView addSubview:snapView];
    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
        snapView.frame = toVC.FromVC.frame;
    } completion:^(BOOL finished) {
        toVC.FromVC.hidden = NO;
        [snapView removeFromSuperview];
        [transitionContext completeTransition:YES];
    }];
}
@end
